package com.hjm.common.utils;

/**
 * @ClassName TimeCostUtil
 * @Author Administrator
 * @Version 1.0
 **/
public class TimeCostUtil {

    private static final ThreadLocal<Long> TIMEOUT_LOCAL = new ThreadLocal<Long>() {
        @Override
        protected Long initialValue() {
            return System.currentTimeMillis();
        }
    };

    /**
     * 开始计时
     */
    public static void begin() {
        Long l = System.currentTimeMillis();
        TIMEOUT_LOCAL.set(l);
    }

    /**
     * 结束计时
     *
     * @return
     */
    public static Long end() {
        Long cost = System.currentTimeMillis() - TIMEOUT_LOCAL.get();
        TIMEOUT_LOCAL.remove();
        return cost;
    }

    /**
     * 获取开始时间
     *
     * @return
     */
    public static Long get() {
        return TIMEOUT_LOCAL.get();
    }

}
